package com.shencai.demo.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shencai.demo.base.entity.SysUser;
import com.shencai.demo.base.service.SysUserService;
import com.shencai.demo.base.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sckj
 * @description 针对表【sys_user(用户表)】的数据库操作Service实现
 * @createDate 2022-10-19 11:04:48
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements SysUserService{

    @Override
    public List<SysUser> getSysUser(String account, String username) {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(SysUser::getAccount,account == null ? "":account).like(SysUser::getUsername,username == null ? "":username);
        List<SysUser> sysUsers = baseMapper.selectList(queryWrapper);
        return sysUsers;
    }

    @Override
    public boolean saveAccount(SysUser sysUser) {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getAccount,sysUser.getAccount());
        SysUser user = baseMapper.selectOne(queryWrapper);
        if (user == null){
            return this.save(sysUser);
        }
        return false;
    }

    /**
     * 用户授权页面查询用户分页
     * @param account
     * @param phone
     * @param username
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public Page<SysUser> ListRoleBypage(String account, String phone, String username, Integer currentPage, Integer pageSize) {
        Page<SysUser> userPage = new Page<>(currentPage,pageSize);
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(SysUser::getAccount,account == null ? "":account)
                .like(SysUser::getPhone,phone == null ? "":phone)
                .like(SysUser::getUsername,username == null ? "":username);
        Page<SysUser> users = baseMapper.selectPage(userPage,queryWrapper);
        return users;
    }
}




